// 版权所有2009 Go作者。版权所有。
// 此源代码的使用受BSD样式
// 许可证的约束，该许可证可以在许可证文件中找到。

package syscall

import (
	"internal/abi"
	"unsafe"
)

func setTimespec(sec, nsec int64) Timespec {
	return Timespec{Sec: sec, Nsec: nsec}
}

func setTimeval(sec, usec int64) Timeval {
	return Timeval{Sec: sec, Usec: int32(usec)}
}

// sys Fstat（fd int，stat*stat_t）（error error）=sys fstat64 
// sys Fstatfs（fd int，stat*Statfs_t）（error error）=sys fstatfs64 
// sysnb Gettimeofday（tp*Timeval）（error error）
// sys Lstat（路径字符串，stat*stat_t）（error error）=sys at64 
// SYS Statfs（路径字符串，stat*Statfs\t）（错误）=SYS\u statfs64 
// SYS fstatat（fd int，路径字符串，stat*stat\t，flags int）（错误）=SYS fstat64 
// SYS ptrace1（请求int，pid int，addr uintpttr，数据uintpttr）（错误）=SYS\ptrace 

func SetKevent(k *Kevent_t, fd, mode, flags int) {
	k.Ident = uint64(fd)
	k.Filter = int16(mode)
	k.Flags = uint16(flags)
}

func (iov *Iovec) SetLen(length int) {
	iov.Len = uint64(length)
}

func (msghdr *Msghdr) SetControllen(length int) {
	msghdr.Controllen = uint32(length)
}

func (cmsg *Cmsghdr) SetLen(length int) {
	cmsg.Len = uint32(length)
}

func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
	var length = uint64(count)

	_, _, e1 := syscall6(abi.FuncPCABI0(libc_sendfile_trampoline), uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0)

	written = int(length)

	if e1 != 0 {
		err = e1
	}
	return
}

func libc_sendfile_trampoline()

// go:cgo\u import\u dynamic libc\u sendfile sendfile”/usr/lib/libSystem.B.dylib“

// 在运行时包（runtime/SYS\u darwin\u 64.go）
func syscallX(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno)
